import java.util.Scanner;

class ArrayUtil {
    int findMax(int[] arr,int begin, int end) throws IllegalArgumentException {
        if( begin>=end ){
            throw new IllegalArgumentException( "java.lang.IllegalArgumentException: begin:"+begin +" >= " +"end:"+end);
        }
        else if( begin<0) {
            throw new IllegalArgumentException( "java.lang.IllegalArgumentException: begin:"+begin +" < 0 " );
        }
        else if(end>arr.length) {
            throw new IllegalArgumentException( "java.lang.IllegalArgumentException: end:"+end +" > " +"arr.length");
        }
        int max = arr[begin];
        for(int i=begin ;i<end;i++) {
            if( max<arr[i]){
                max = arr[i];
            }
        }
        return max;
    }
}
public class Main {

    public static void main(String[] args) {
        Scanner sc= new Scanner(System.in);
        ArrayUtil arrayUtil = new ArrayUtil();
        int n = sc.nextInt();
        int [] arr = new int[n];
        for(int i=0;i<n;i++) {
            arr[i] = sc.nextInt();
        }
        int m = sc.nextInt();
        int count =0;
        for(int i=0;i<m;i++) {
            int a = sc.nextInt();
            int b = sc.nextInt();
            try {
                System.out.println(arrayUtil.findMax(arr, a, b));
            } catch (Exception e) {
                System.out.println(e.getMessage());

            }
        }

    }

}

